<?php
/**
 * Created by PhpStorm.
 * User: lzh 9157374
 * Date: 2018/5/20
 * Time: 上午11:18
 */
namespace Core\common;

class Request
{
    /**
     * 请求参数
     * @param string $key
     * @param string $default
     * @return mixed|string
     */
    public static function params($key = '',$default = '')
    {
        if($key){
            return Assist::gpcVal($key,$default);
        }
        
        $data = self::_filterParams();
        return $data;
    }

    /**
     * 过滤请求中的参数
     * @return mixed
     */
    private static function _filterParams()
    {
        $yWe7 = Assist::globalVal('yWe7');
        $filterArr = [
            'c','a','eid','version_id','m','do','i',
            'state','op',$yWe7['action_name'],'message','jsMenuScroll'
        ];
        $filterArr = array_unique(array_filter($filterArr));
        $params = Assist::gpcVal('.');

        foreach ($params as $k => $v) {
            if(in_array($k,$filterArr)){
                unset($params[$k]);
                continue;
            }
            if(strpos($k,'__') === 0){
                unset($params[$k]);
                continue;
            }
            if(strpos($k,'module_status') === 0){
                unset($params[$k]);
            }
        }
        
        return $params;
    }
    
    public static function url($base = false)
    {
        if($base){
            return trim(Assist::globalVal('siteroot'),'/');
        }
        return Assist::globalVal('siteurl');
    }

    public static function isPost()
    {
        return Assist::globalVal('ispost');
    }

    public static function isAjax()
    {
        return Assist::globalVal('isajax');
    }
}